package com.yunxi.controller.dealer;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.dealer.pojo.BusinessVO;
import com.yunxi.dealer.service.BusinessDubboService;
import com.yunxi.sys.pojo.AreaVO;
import com.yunxi.sys.service.AreaDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * <p>
 * 渠道商业务类型信息 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-21
 */
@RestController
@RequestMapping("/admin/partner/area")
@Api(tags = "partner:area", description = "渠道商归属地区/管辖范围接口")
public class PartnerAreaController {
   private static final Logger logger = LoggerFactory.getLogger(PartnerAreaController.class);
   @Autowired
   AreaDubboService areaDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询不在该大区的省份")
   public ApiResult page(AreaVO areaVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(areaDubboService.findPageByVO(areaVO, pageNum, pageSize));
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(AreaVO areaVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(areaDubboService.getById(areaVO.getAreaId()));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody AreaVO areaVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      areaDubboService.saveOrUpdate(areaVO);
      return ResponseUtil.ok("success");
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询")
   public ApiResult list(@RequestParam Map<String,String> params) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
      return  ResponseUtil.ok(areaDubboService.listByPid(params.get("pid")));
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody AreaVO areaVO) throws Exception {
      areaDubboService.removeById(areaVO.getAreaId());
      return ResponseUtil.ok("success");
   }

//   @GetMapping("/treeByPid")
//   @ApiOperation(value = "组织树形查询")
//   public ApiResult treeByPid(String pid) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
//      return (ApiResult) areaDubboService.treeByPid();
//   }

//   @GetMapping("/listProvince")
//   @ApiOperation(value = "组织树形查询")
//   public ApiResult listProvince() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
//      return (ApiResult)areaDubboService.listProvince();
//   }

   @GetMapping("/treeByType")
   @ApiOperation(value = "渠道树形查询")
   public ApiResult treeByType(@RequestParam Integer type) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
      return (ApiResult) areaDubboService.treeByType(type);
   }
/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(businessDubboService.findMapByList(params));
}*/
}
